package test.h0819;

import java.util.*;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 会议室占用时间
 * @date 2024/8/19 21:03
 */
public class Main4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] times = new int[n][2];
        for (int i = 0; i < n; i++) {
            times[i][0] = sc.nextInt();
            times[i][1] = sc.nextInt();
        }
        getRes(times, n);
    }

    private static void getRes(int[][] times, int n) {
        List<int[]> ans = new ArrayList<>();
        //按照开始时间排序
        Arrays.sort(times, Comparator.comparingInt(o -> o[0]));
        int start = times[0][0];
        int end = times[0][1];
        int i = 1;
        while (i < n) {
            //证明有交集
            while (i<n&&end >= times[i][0]) {
                if (end < times[i][1]) {
                    end = times[i][1];
                }
                i++;
            }
            //TODO 注意极端情况的判断，后面考试极其要注意
            if (i>=n)  break;
            ans.add(new int[]{start, end});
            start = times[i][0];
            end = times[i][1];
            i++;
        }
        ans.add(new int[]{start,end});
        for (int[] a : ans) {
            System.out.println(a[0]+" "+a[1]);
        }
    }
}
